"""
基本介绍
1）== 是一个比较运算符：对象之间进行比较时，比较的是内存地址是否相同，判断是不是同一个对象
2）重写 __eq__ 方法，可以用于判断对象内容/属性是否相等

"""

class Person:
    name = None
    age = None
    gender = None

    def __init__(self, name, age, gender):
        self.name = name
        self.age = age
        self.gender = gender

    def __eq__(self, other):
        if not isinstance(other, Person):
            return False
        return self.name == other.name and self.age == other.age and self.gender == other.gender

    def __lt__(self, other):
        if not isinstance(other, Person):
            return False
        return self.age < other.age

    def __le__(self, other):
        if not isinstance(other, Person):
            return False
        return self.age <= other.age

    def __gt__(self, other):
        if not isinstance(other, Person):
            return False
        return self.age > other.age

    def __ge__(self, other):
        if not isinstance(other, Person):
            return False
        return self.age >= other.age

    def __ne__(self, other):
        return not self.__eq__(other)

# 没有重写 __eq__ 前，== 比较的是内存地址
p1 = Person("smith", 20, "男")
p2 = Person("smith", 20, "男")
print(p1 == p2)